
//
//  Goods_Product_View.m
//  MindBox
//
//  Created by MS on 16-1-15.
//  Copyright (c) 2016年 Lemon. All rights reserved.
//

#import "Goods_Product_View.h"
#import "UIView+Frame.h"
@interface Goods_Product_View ()

@property (weak, nonatomic) IBOutlet UIView *descView;

@property (weak, nonatomic) IBOutlet UILabel *titleView;
@property (weak, nonatomic) IBOutlet UILabel *p_priceView;
@property (weak, nonatomic) IBOutlet UILabel *priceView;

@property (weak, nonatomic) IBOutlet UILabel *saleCountView;
@property (weak, nonatomic) IBOutlet UILabel *likeCountView;
@property (weak, nonatomic) IBOutlet UIView *wayPag;
@property (weak, nonatomic) IBOutlet UIView *labelsBaseView;

@property (nonatomic,strong) NSMutableArray * labArray;

@property (nonatomic,weak) UIView * lin;

@end

@implementation Goods_Product_View

-(NSMutableArray *)labArray
{
    if (_labArray==nil) {
        _labArray = [NSMutableArray array];
    }
    return _labArray;
}

-(void)setGoodsDetailData:(GoodsDetailModel *)goodsDetailData
{
    _goodsDetailData = goodsDetailData;
    
    _titleView.text = goodsDetailData.name;
    
    NSString * p_price = [NSString stringWithFormat:@"¥ %.2f",[[goodsDetailData.products[0] p_price] floatValue]];
    _p_priceView.text = p_price;
    
     NSString * price = [NSString stringWithFormat:@"¥ %.2f",[[goodsDetailData.products[0] price] floatValue]];
    _priceView.text = price;
   

    
    NSString * seal = [NSString stringWithFormat:@"送出%@次",goodsDetailData.sale_count];
    _saleCountView.text = seal;
    
      NSString * like = [NSString stringWithFormat:@"收藏%@人",goodsDetailData.like_count];
    _likeCountView.text = like;
    
    [_labArray removeAllObjects];
    for (Goods_Label_List * item in goodsDetailData.label_list) {
        
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.titleEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 10);
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setTitle:item.label_name forState:UIControlStateNormal];
        
        btn.titleLabel.font = [UIFont systemFontOfSize:10];
        btn.layer.borderColor = [[UIColor blackColor] CGColor];
        
        btn.layer.borderWidth = 0.5;
       
        
        [btn sizeToFit];
        
        [_labelsBaseView addSubview:btn];
        [self.labArray addObject:btn];
    }
    
    

    [self layoutSubviews];
}



+(instancetype)goods_product_ViewWithXib
{
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
}


-(void)awakeFromNib
{
    _descView.backgroundColor = [UIColor colorWithRed:0.98f green:0.98f blue:0.98f alpha:1.00f];
    UIView * lin = [[UIView alloc] initWithFrame:CGRectMake(0, _priceView.height*0.5, _priceView.width, 1)];
    [_priceView addSubview:lin];
    self.lin = lin;
    lin.backgroundColor = [UIColor grayColor];
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    [self.priceView setNeedsLayout];
    [self.priceView layoutIfNeeded];
    
     self.lin.frame = CGRectMake(0, _priceView.height*0.5, _priceView.width, 1);
    
    CGFloat margin = 10;
    CGFloat x= 0;
    for (UILabel * item in self.labArray) {
        
        item.x = x+ margin;
        item.y = (_labelsBaseView.height - item.height)*0.5;
        item.width =item.width +20;
        x = x+ margin + item.width;
    }
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
